<template>
  <div class="icons">

    <swiper :options="swiperOption">
        <swiper-slide  v-for="(page,index) in pages" :key="index">
          <div class="icon"   v-for=" item in page" >

              <div class="icon-img">
                <img class="icon-img-content" :src="item.imgUrl" >
                <!--犯了个sb错，把content写成conteng，导致样式不生效。记住错误-->
              </div>
              <p class="icon-desc">{{item.desc}}</p>
          </div>
        </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>

    </swiper>

  </div>
</template>

<script>
  export default {
    name: 'HomeIcons',

    data:function(){
      return {
        swiperOption:{

          loop:true,
          autoplay:false,



        }
      }
    },
   props:{
      list:Array
   },
    computed:{
      pages(){/*非常棒的方法把，数据由一个大数组分成多个数组，每个数组8个*/
        const pages=[];
        this.list.forEach((item,index)=>{
          const page=Math.floor(index/8);
          if(!pages[page]){
             pages[page]=[];
          }
          pages[page].push(item)
        });
        return pages
      },


    }


  }
</script>

<style lang="stylus" scoped>
  /*犯了个错误，把lang写成type了*/
  /*@import '../../../assets/styles/varibles.styl'*/
  @import '~styles/varibles.styl' /*   'styles':resolve('src/assets/styles')   在webpack.base.conf.js设置生效*/
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
     /*background:red;*/
     height:0;
     padding-bottom:50%;/*又犯sb错误，写成bottom-padding记住*/
  .icons
    background:#fff;
    width:100%
    box-sizing:border-box;

    .icon
      -webkit-box-sizing: border-box;
      width:25%;
      height:0;
      padding-bottom:25%;
      overflow:hidden;
      float:left;
      position:relative;
      text-align:center;
      .icon-img
        position:absolute;
        top:0;
        left:0;
        right:0;
        bottom:.44rem
        .icon-img-content
           display:block;
           margin:0 auto;
           height:100%;
      .icon-desc
        position:absolute;
        left:0;
        right:0;
        bottom:0;
        height:.44rem;
        line-height:0.44rem;
        color:$darkTextColor;
        ellipsis()
        /*overflow:hidden;  用来设置省略号显示
        text-overflow:ellipsis;
        white-space :nowrap;*/
</style>
